var vm = new Vue({
	el:'#slothMain',
	data:{
		msgLogData: [],//日志消息
		queueData: [],//队列名称
		queue2TypeData: [],
		msgStatusCount: {},
		refreshTimeOutId: null,
		refreshTime: 5,
		currentTime: new Date()
	},
	mounted() {
		this.loadMsgQueue();
		this.loadQueue2Type();
		
		this.refreshMsgLog();
		this.rebootRefreshMsgLogMethod();
		
		setInterval(function(){vm.currentTime = new Date();}, 1000);
	},
	watch: {
		refreshTime : function(val) {
			this.rebootRefreshMsgLogMethod();
		}
	},
	methods: {
		//刷新消息日志列表
		loadMsgLog : function() {
			$.ajax({
				type: "POST",
			    url: "./sloth/log/list",
                contentType: "application/json",
			    success: function(r){
			    	if(r.code === 0){
			    		if(vm.util.isEmpty(r.data)){
			    			vm.msgLogData = [];
			    		} else {
			    			vm.msgLogData = r.data;
			    		}
					} else {
						alert(r.msg);
					}
				}
			});
		},
		loadMsgQueue: function(){
			$.ajax({
				type: "POST",
			    url: "./sloth/log/queue/list",
                contentType: "application/json",
			    success: function(r){
			    	if(r.code === 0){
			    		if(vm.util.isEmpty(r.data)){
			    			vm.queueData = [];
			    		} else {
			    			vm.queueData = r.data;
			    		}
					} else {
						alert(r.msg);
					}
				}
			});
		},
		loadQueue2Type: function(){
			$.ajax({
				type: "POST",
			    url: "./sloth/log/queue2Type/list",
                contentType: "application/json",
			    success: function(r){
			    	if(r.code === 0){
			    		if(vm.util.isEmpty(r.data)){
			    			vm.queue2TypeData = [];
			    		} else {
			    			vm.queue2TypeData = r.data;
			    		}
					} else {
						alert(r.msg);
					}
				}
			});
		},
		loadMsgStatusCount : function() {
			$.ajax({
				type: "POST",
			    url: "./sloth/log/countStatus",
                contentType: "application/json",
			    success: function(r){
			    	if(r.code === 0){
			    		if(vm.util.isEmpty(r.data)){
			    			vm.msgStatusCount = {};
			    		} else {
			    			vm.msgStatusCount = r.data;
			    		}
					} else {
						alert(r.msg);
					}
				}
			});
		},
		clearMsgQueue: function(msgQueueName){
			$.ajax({
				type: "POST",
			    url: "./sloth/log/clearQueue",
                data: {
                	queueName: msgQueueName
                },
			    success: function(r){
			    	alert(r.msg);
			    	if(r.code === 0){
			    		vm.loadMsgQueue();
			    		vm.loadQueue2Type();
					}
				}
			});
		},
		getRowClass : function(status){
			if("1" == status) {
				return "active";
			} else if("2" == status) {
				return "info";
			} else if("3" == status) {
				return "success";
			} else if("4" == status) {
				return "danger";
			} else {
				return "";
			}
		},
		getDealStatusWord : function(status){
			if("1" == status) {
				return "待处理";
			} else if("2" == status) {
				return "处理中";
			} else if("3" == status) {
				return "成功";
			} else if("4" == status) {
				return "失败";
			} else {
				return "-";
			}
		},
		refreshMsgLog : function(){
			this.loadMsgLog();
			this.loadMsgStatusCount();
		},
		rebootRefreshMsgLogMethod : function() {
			if(this.util.isNotEmpty(this.refreshTimeOutId)){
				clearInterval(this.refreshTimeOutId);
			}
			
			this.refreshTimeOutId = setInterval(function(){vm.refreshMsgLog();}, this.refreshTime * 1000);
			console.log("refreshTimeOutId = " + this.refreshTimeOutId);
		},
		goToListOfDealStatus : function(dealStatus){
			window.location.href = "./listOfDealStatus.html?dealStatus=" + dealStatus;
		},
		goToMsgLogDtl : function(id){
			window.location.href = "./msgLogDtl.html?id=" + id;
		},
		clearAllMsgLog: function(){
			$.ajax({
				type: "POST",
			    url: "./sloth/log/clearAll",
                contentType: "application/json",
			    success: function(r){
			    	alert(r.msg);
			    	window.location.reload();
				}
			});
		}
	}
});